<template>
	<view style="box-sizing: border-box; padding:0 20px; ">
		<view style="border: #ccc dashed 1px; padding:8px 10px;border-radius: 6px; margin-top: 40px; ">
			<view class="flex f14 a-t">
				<image src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/xin1.png" style="width: 26px; margin-right:4px" mode="widthFix"></image>
				<input type="text" v-model="form.name" :disabled="!edit_switch" placeholder="纪念日名称" />
			</view>
		</view>
		<view style="border: #ccc dashed 1px; padding:8px 10px;border-radius: 6px; margin-top: 40px; ">
			<view class="flex f14 a-t">
				<image src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/naozhong.png" style="width: 26px; margin-right:4px" mode="widthFix"></image>

				<picker mode="date" :value="form.date" :start="startDate" @change="DateChange" data-target="date">
					<view class="picker"><input type="text" v-model="form.date" placeholder="请选择日期" /></view>
				</picker>
			</view>
		</view>
		<view @click="submit" class="button f14" style="width: 120px; text-align: center; line-height: 40px; margin: 40px auto; ">确认保存</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			form: {
				date: '',
				name: ''
			},
			type: '',
			edit_switch: 1
		};
	},
	onReady() {
		// this.time=this.date.getYear()
		console.log(this.vuex_user_content, 'this.vuex_user_content.id');
	},
	onLoad(e) {
		// console.log(JSON.parse(e.item), 'ggggggggggggg');
		if (e.item) {
			const item = JSON.parse(e.item);
			this.type = 1;
			this.form.anniversary_id = item.id;
			this.form.name = item.name;
			this.form.date = item.date;
			this.edit_switch = item.edit_switch;
		}
	},
	methods: {
		async submit() {
			let res = null;
			if (this.type == 1) {
				res = await this.$u.api.edit(this.form);
			} else {
				this.form.my_space_id = this.vuex_user_content.id;
				res = await this.$u.api.addcreate(this.form);
			}
			if (res) {
				uni.showToast({
					title: this.type == 1 ? '编辑成功' : '创建成功',
					icon: 'none'
				});
				setTimeout(function () {
                    uni.navigateBack({});
                }, 1500)
			}
		},
		DateChange(e) {
			console.log(e);
			this.form.date = e.detail.value;
		}
	}
};
</script>

<style>
page {
	background: #fff;
}
</style>
